package com.visionblue.business.ship.model.api

import android.app.Application
import com.visionblue.business.ship.App
import com.visionblue.business.ship.BuildConfig
import com.visionblue.business.ship.model.api.ParamsInterceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit

/**
 * @author: xlh
 * @date: 2020-04-10 2:28 PM
 * @desc:
 */
class OkHttpClientProvider {

    companion object {
        val client: OkHttpClient = OkHttpClient.Builder()
            .writeTimeout(10, TimeUnit.SECONDS)
            .connectTimeout(10, TimeUnit.SECONDS)
            .callTimeout(30, TimeUnit.SECONDS)
            .addInterceptor(getLoggerInterceptor())
//            .addInterceptor(UserAgentInterceptor())
            .addInterceptor(ParamsInterceptor((App.context as App).deviceInfoRepository))
            .build()

        private fun getLoggerInterceptor() = HttpLoggingInterceptor().apply {
            level = if (BuildConfig.LOG_DEBUG) {
                HttpLoggingInterceptor.Level.BODY
            } else {
                HttpLoggingInterceptor.Level.NONE
            }
        }





    }
}